import { data } from 'autoprefixer';
import axios from 'axios';

const service = axios.create({
  baseURL: '',
  timeout: 5000,
});

// 请求拦截
service.interceptors.request.use(
  (config) => {
    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

// 响应拦截
service.interceptors.response.use((response) => {
  const { success, message, data } = Promise.resolve(response.data);
  if (success) {
    return data;
  } else {
    return Promise.reject(new Error(message));
  }
});

export default service;
